package repository

import (
	"gitee.com/ling1314/origin-utility/db"
	"gitee.com/ling1314/origin-utility/model"
)

type idpLogRepository struct{}

func (r idpLogRepository) SaveLogCpu(m *model.IdpLogCpu) (err error) {
	return db.GetDB().Save(m).Error
}
func (r idpLogRepository) FindLastCpu(id int64) (m model.IdpLogCpu, err error) {
	err = db.GetDB().Where("device_id = ? ", id).
		Order("created_at desc").Limit(1).Find(&m).Error
	return
}
func (r idpLogRepository) SaveLogMemory(m *model.IdpLogMemory) (err error) {
	return db.GetDB().Save(m).Error
}

func (r idpLogRepository) FindLastMemory(id int64) (m model.IdpLogMemory, err error) {
	err = db.GetDB().Where("device_id = ? ", id).
		Order("created_at desc").Limit(1).Find(&m).Error
	return
}

func (r idpLogRepository) SaveLogDisk(m *model.IdpLogDisk) (err error) {
	return db.GetDB().Save(m).Error
}

func (r idpLogRepository) FindLastDisk(id int64) (m model.IdpLogDisk, err error) {
	err = db.GetDB().Where("device_id = ? ", id).
		Order("created_at desc").Limit(1).Find(&m).Error
	return
}

func (r idpLogRepository) SaveLogBoard(m *model.IdpLogBoard) (err error) {
	return db.GetDB().Save(m).Error
}

func (r idpLogRepository) FindLastBoard(id int64) (m model.IdpLogBoard, err error) {
	err = db.GetDB().Where("device_id = ? ", id).
		Order("created_at desc").Limit(1).Find(&m).Error
	return
}

func (r idpLogRepository) SaveLogSysAbstract(m *model.IdpLogSysAbstract) (err error) {
	return db.GetDB().Save(m).Error
}
func (r idpLogRepository) FindLastSysAbstract(id int64) (m model.IdpLogSysAbstract, err error) {
	err = db.GetDB().Where("device_id = ? ", id).
		Order("created_at desc").Limit(1).Find(&m).Error
	return
}

func (r idpLogRepository) SaveLogApp(m *model.IdpLogApp) (err error) {
	return db.GetDB().Save(m).Error
}

func (r idpLogRepository) FindLastApp(id int64) (m model.IdpLogApp, err error) {
	err = db.GetDB().Where("device_id = ? ", id).
		Order("created_at desc").Limit(1).Find(&m).Error
	return
}

func (r idpLogRepository) SaveAppChangeLog(li []model.IdpAppChangeLog) (err error) {
	return db.GetDB().Save(&li).Error
}
